﻿using System.Threading.Tasks;
using MongoDB.Driver;
using Sustainalytics.Entities.RiskRatings;

namespace Sustainalytics.ClientDW.Synchronization.SyncRiskRatingsData
{
    public class CoreRiskRatingResearchProfileIndexes
    {
        public static async Task RecreateIndexes(IMongoCollection<CoreRiskRatingResearchProfile> collection)
        {
            await collection.Indexes.CreateOneAsync(Builders<CoreRiskRatingResearchProfile>.IndexKeys.Ascending(x => x.Id)).ConfigureAwait(false);
            await collection.Indexes.CreateOneAsync(Builders<CoreRiskRatingResearchProfile>.IndexKeys.Ascending(x => x.CompanyId)).ConfigureAwait(false);
            await collection.Indexes.CreateOneAsync(Builders<CoreRiskRatingResearchProfile>.IndexKeys.Ascending(x => x.SubPeerGroupId)).ConfigureAwait(false);
            await collection.Indexes.CreateOneAsync(Builders<CoreRiskRatingResearchProfile>.IndexKeys.Ascending(x => x.Assessment)).ConfigureAwait(false);

            CreateIndexOptions options = new CreateIndexOptions { Collation = new Collation(locale: "en", caseLevel: true, strength: CollationStrength.Primary) };

            await collection.Indexes.CreateOneAsync(Builders<CoreRiskRatingResearchProfile>.IndexKeys.Ascending(x => x.CompanyName), options).ConfigureAwait(false);
            await collection.Indexes.CreateOneAsync(Builders<CoreRiskRatingResearchProfile>.IndexKeys.Ascending(x => x.Exchange), options).ConfigureAwait(false);
            await collection.Indexes.CreateOneAsync(Builders<CoreRiskRatingResearchProfile>.IndexKeys.Ascending(x => x.Ticker), options).ConfigureAwait(false);
            await collection.Indexes.CreateOneAsync(Builders<CoreRiskRatingResearchProfile>.IndexKeys.Ascending(x => x.SubPeerGroup), options).ConfigureAwait(false);
            await collection.Indexes.CreateOneAsync(Builders<CoreRiskRatingResearchProfile>.IndexKeys.Ascending(x => x.LastUpdate), options).ConfigureAwait(false);
        }
    }
}
